/*=============================================================================
    test/dialogTest.js
    Copyright (C) 2008-2009, Donald W. Griffin
    All rights reserved.
    [MIT license :: see license.txt for details]
=============================================================================*/
$module("test.dialogTest");

$requires("test.placementTest");

$requires("jibits.dialog");
$requires("test.base");

$namespace(test, {

Dialog1 : $class(jibits.Dialog,
{
    ctor : function (id)
    {
        var dismiss = this.dismiss.bind(this);

        $super(arguments).call(this, id,
                    {
                        modal : true,
                        modalStyle : "testModalPane",
                        defChild : "ok1",
                        hotkeys :
                        {
                            enter  : "ok1",
                            esc    : "cancel1",
                            d      : "dlg1"
                        },
                        commands :
                        {
                            ok1     : dismiss.head(true),
                            cancel1 : dismiss.head(false),
                            dlg1    : this.ondlg.bind(this)
                        }
                    });
    },

    onInit : function ()
    {
        $super(arguments, this);

        this.pop = $widget("popup1");
    },

    onPreShow : function ()
    {
        this.moveTo($rect(340, 100, 0, 0));
    },

    onClickOut : function ()
    {
        this.hide();
    },

    ondlg : function ()
    {
        if (!this.dlg)
            this.dlg = new test.Dialog2("dlg");

        this.dlg.placeAdjacent("0%,0%", this, "0%+70,0%+50");
        this.dlg.execute();
    }
}),

dialogTemplateCfg :
{
    pop : { $text : "#{name}!!" }
},

Dialog2 : $class(jibits.Dialog,
{
    ctor : function (id)
    {
        var dismiss = this.dismiss.bind(this);

        $super(arguments).call(this, id,
                     {
                         defChild: "edit",
                         modal: true,
                         template: $widget("dialogTemplate"),
                         //new jibits.Template("dialogTemplate",
                         //   {
                         //       pop : { $text : "#{name}!!" }
                         //   }),
                         ctx: {
                             title : "Dlg",
                             name : "Dude"
                         },
                         hotkeys : {
                             enter : "ok",
                             esc : "cancel"
                         },
                         commands : {
                             ok : {
                                 handler : dismiss.head(true),
                                 enabler : function (en)
                                 {
                                     var s = this.getChild("edit").value;
                                     en.enable(s.length > 3);
                                 }.bind(this)
                             },
                             cancel : dismiss.head(false)
                         }
                     });
    },

    onInit : function ()
    {
        // second wrapper for the same element:
        this.pop = new test.PlacementTester("popup1",
                                            { ref : this.getChildId("pop") });
    }
})

}) // namespace test
